1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module adw.Animation; 26 27 private import adw.AnimationTarget; 28 private import adw.c.functions; 29 public import adw.c.types; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import gtk.Widget; 33 private import std.algorithm; 34 35 36 /** 37 * A base class for animations. 38 * 39 * `AdwAnimation` represents an animation on a widget. It has a target that 40 * provides a value to animate, and a state indicating whether the 41 * animation hasn't been started yet, is playing, paused or finished. 42 * 43 * Currently there are two concrete animation types: 44 * [class@TimedAnimation] and [class@SpringAnimation]. 45 * 46 * `AdwAnimation` will automatically skip the animation if 47 * [property@Animation:widget] is unmapped, or if 48 * [property@Gtk.Settings:gtk-enable-animations] is `FALSE`. 49 * 50 * The [signal@Animation::done] signal can be used to perform an action after 51 * the animation ends, for example hiding a widget after animating its 52 * [property@Gtk.Widget:opacity] to 0. 53 * 54 * `AdwAnimation` will be kept alive while the animation is playing. As such, 55 * it's safe to create an animation, start it and immediately unref it: 56 * A fire-and-forget animation: 57 * 58 * ```c 59 * static void 60 * animation_cb (double value, 61 * MyObject *self) 62 * { 63 * // Do something with @value 64 * } 65 * 66 * static void 67 * my_object_animate (MyObject *self) 68 * { 69 * AdwAnimationTarget *target = 70 * adw_callback_animation_target_new ((AdwAnimationTargetFunc) animation_cb, 71 * self, NULL); 72 * g_autoptr (AdwAnimation) animation = 73 * adw_timed_animation_new (widget, 0, 1, 250, target); 74 * 75 * adw_animation_play (animation); 76 * } 77 * ``` 78 * 79 * If there's a chance the previous animation for the same target hasn't yet 80 * finished, the previous animation should be stopped first, or the existing 81 * `AdwAnimation` object can be reused. 82 * 83 * Since: 1.0 84 */ 85 public class Animation : ObjectG 86 { 87 /** the main Gtk struct */ 88 protected AdwAnimation* adwAnimation; 89 90 /** Get the main Gtk struct */ 91 public AdwAnimation* getAnimationStruct(bool transferOwnership = false) 92 { 93 if (transferOwnership) 94 ownedRef = false; 95 return adwAnimation; 96 } 97 98 /** the main Gtk struct as a void* */ 99 protected override void* getStruct() 100 { 101 return cast(void*)adwAnimation; 102 } 103 104 /** 105 * Sets our main struct and passes it to the parent class. 106 */ 107 public this (AdwAnimation* adwAnimation, bool ownedRef = false) 108 { 109 this.adwAnimation = adwAnimation; 110 super(cast(GObject*)adwAnimation, ownedRef); 111 } 112 113 114 /** */ 115 public static GType getType() 116 { 117 return adw_animation_get_type(); 118 } 119 120 /** 121 * Gets the current value of @self. 122 * 123 * The state indicates whether @self is currently playing, paused, finished or 124 * hasn't been started yet. 125 * 126 * Returns: the animation value 127 * 128 * Since: 1.0 129 */ 130 public AdwAnimationState getState() 131 { 132 return adw_animation_get_state(adwAnimation); 133 } 134 135 /** 136 * Gets the target @self animates. 137 * 138 * Returns: the animation target 139 * 140 * Since: 1.0 141 */ 142 public AnimationTarget getTarget() 143 { 144 auto __p = adw_animation_get_target(adwAnimation); 145 146 if(__p is null) 147 { 148 return null; 149 } 150 151 return ObjectG.getDObject!(AnimationTarget)(cast(AdwAnimationTarget*) __p); 152 } 153 154 /** 155 * Gets the current value of @self. 156 * 157 * Returns: the current value 158 * 159 * Since: 1.0 160 */ 161 public double getValue() 162 { 163 return adw_animation_get_value(adwAnimation); 164 } 165 166 /** 167 * Gets the widget @self was created for. 168 * 169 * Returns: the animation widget 170 * 171 * Since: 1.0 172 */ 173 public Widget getWidget() 174 { 175 auto __p = adw_animation_get_widget(adwAnimation); 176 177 if(__p is null) 178 { 179 return null; 180 } 181 182 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 183 } 184 185 /** 186 * Pauses a playing animation for @self. 187 * 188 * Does nothing if the current state of @self isn't `ADW_ANIMATION_PLAYING`. 189 * 190 * Sets [property@Animation:state] to `ADW_ANIMATION_PAUSED`. 191 * 192 * Since: 1.0 193 */ 194 public void pause() 195 { 196 adw_animation_pause(adwAnimation); 197 } 198 199 /** 200 * Starts the animation for @self. 201 * 202 * If the animation is playing, paused or has been completed, restarts it from 203 * the beginning. This allows to easily play an animation regardless of whether 204 * it's already playing or not. 205 * 206 * Sets [property@Animation:state] to `ADW_ANIMATION_PLAYING`. 207 * 208 * The animation will be automatically skipped if [property@Animation:widget] is 209 * unmapped, or if [property@Gtk.Settings:gtk-enable-animations] is `FALSE`. 210 * 211 * As such, it's not guaranteed that the animation will actually run. For 212 * example, when using [func@GLib.idle_add] and starting an animation 213 * immediately afterwards, it's entirely possible that the idle callback will 214 * run after the animation has already finished, and not while it's playing. 215 * 216 * Since: 1.0 217 */ 218 public void play() 219 { 220 adw_animation_play(adwAnimation); 221 } 222 223 /** 224 * Resets the animation for @self. 225 * 226 * Sets [property@Animation:state] to `ADW_ANIMATION_IDLE`. 227 * 228 * Since: 1.0 229 */ 230 public void reset() 231 { 232 adw_animation_reset(adwAnimation); 233 } 234 235 /** 236 * Resumes a paused animation for @self. 237 * 238 * This function must only be used if the animation has been paused with 239 * [method@Animation.pause]. 240 * 241 * Sets [property@Animation:state] to `ADW_ANIMATION_PLAYING`. 242 * 243 * Since: 1.0 244 */ 245 public void resume() 246 { 247 adw_animation_resume(adwAnimation); 248 } 249 250 /** 251 * Skips the animation for @self. 252 * 253 * If the animation hasn't been started yet, is playing, or is paused, instantly 254 * skips the animation to the end and causes [signal@Animation::done] to be 255 * emitted. 256 * 257 * Sets [property@Animation:state] to `ADW_ANIMATION_FINISHED`. 258 * 259 * Since: 1.0 260 */ 261 public void skip() 262 { 263 adw_animation_skip(adwAnimation); 264 } 265 266 /** 267 * This signal is emitted when the animation has been completed, either on its 268 * own or via calling [method@Animation.skip]. 269 * 270 * Since: 1.0 271 */ 272 gulong addOnDone(void delegate(Animation) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 273 { 274 return Signals.connect(this, "done", dlg, connectFlags ^ ConnectFlags.SWAPPED); 275 } 276 }